package SelectAdmin.impl;

import SelectAdmin.IAdminSelect;
import entity.Admin;
import util工具包.JDBCutil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminSelectImpl implements IAdminSelect {
    @Override//这里需要两个参数
    public Admin selectAdmin(String account, String password) {
            Connection conn = JDBCutil.getconnection();
            PreparedStatement pst=null;
            ResultSet rs= null;
            Admin admin = new Admin();

        try {
                pst = conn.prepareStatement("select account,password from user_admin");
                rs= pst.executeQuery();

                while (rs.next()){

                    String name = rs.getString("account");
                    String pass = rs.getString("password");
                    if (account.equals(name)){
                        admin.setAccount(name);
                        admin.setPassword(pass);
                        return admin;
                    }
                }

            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                JDBCutil.close(conn,pst,rs);
            }
            return null;
        }

//    @Override
//    public Admin selectAdmin(String username,String password) {
//        return null;
//    }
}
